package org.handover.domain;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Range;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.*;

/**
 * @author Copyright ©2017 贾维程. All rights reserved.
 */
@Entity
@Table
public class Handover  implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(generator = "idGenerator")
    @GenericGenerator(name = "idGenerator",strategy = "native")
    private Long id;

    @NotNull(message = "{notnull}")
    @Column(nullable = false)
    @Temporal(TemporalType.DATE)
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date date;

    @NotNull(message = "{notnull}")
    //@DecimalMin(value = "-60",message = "{handover.temperatureMin}")
    //@DecimalMax(value = "100",message = "{handover.temperatureMax}")
    @Range(min = -50, max = 100, message = "{handover.temperature}")
    @Column(nullable = false)
    private double temperature = 24;

    @NotNull(message = "{notnull}")
    @Column(nullable = false)
    @Range(min = 0, max = 100, message = "{handover.humidity}")
    private int humidity = 20;

    @JoinColumn(name = "shift_id", referencedColumnName = "id", nullable = false)
    @ManyToOne
    private Shift shift;

    @JoinColumn(name = "user_id", referencedColumnName = "id", nullable = false)
    @ManyToOne
    private User user;

    @OneToMany(mappedBy = "handover")
    private List<Details> detailsList = new ArrayList<>();

    public Handover() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public double getTemperature() {
        return temperature;
    }

    public void setTemperature(double temperature) {
        this.temperature = temperature;
    }

    public int getHumidity() {
        return humidity;
    }

    public void setHumidity(int humidity) {
        this.humidity = humidity;
    }

    public Shift getShift() {
        return shift;
    }

    public void setShift(Shift shift) {
        this.shift = shift;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<Details> getDetailsList() {
        return detailsList;
    }

    public void setDetailsList(List<Details> detailsList) {
        this.detailsList = detailsList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Handover)) {
            return false;
        }
        Handover other = (Handover) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "hanover.domain.Handover[ id=" + id + " ]";
    }

}
